import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)
import Layout from '@/layout'

import approval from './modules/approval'
import attendance from './modules/attendance'
import department from './modules/department'
import employee from './modules/employee'
import permission from './modules/permission'
import role from './modules/role'
import salary from './modules/salary'
import social from './modules/social'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
    beforeEnter(to, fromxxx, next) {
      next()
    }
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: '首页', icon: 'dashboard' }
    }]
  }

  // 正则路由匹配的内置引擎 path-to-regexp
  // { path: '/params/:foo/:bar' },
  // { path: '/optional-params/:foo?' },
  // { path: '/params-with-regex/:id(\\d+)' },
  // { path: '/asterisk/*' },
  // { path: '/optional-group/(foo/)?bar' },

  // { path: '*', redirect: '/404', hidden: true }
]

export const asyncRoutes = [
  department,
  role,
  employee,
  permission,
  approval,
  attendance,
  salary,
  social
]

const createRouter = () => new Router({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  // routes: [...constantRoutes, ...asyncRoutes]
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  console.log(router, 5555555)
  console.log(111333)
  const newRouter = createRouter()
  router.matcher = newRouter.matcher
}

export default router
